<?php

declare(strict_types=1);

namespace Modules\Inventory\Models;

use Modules\User\Models\User;
use Catch\Base\CatchModel as Model;

/**
 * @property $id
 * @property $docno
 * @property $org_code
 * @property $status
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
*/
class TransferOrder extends Model
{


    protected $table = 'transfer_order';

    protected $fillable = [ 'id', 'docno', 'org_code','order_type','trans_status', 'status', 'creator_id', 'created_at', 'updated_at', 'deleted_at' ];

    /**
     * @var array
     */
    protected array $fields = ['id','docno','org_code','order_type','trans_status','status','created_at','updated_at'];

    /**
     * @var array
     */
    protected array $form = ['id','docno','org_code','order_type','trans_status','status','created_at','updated_at'];

    /**
     * @var array
     */
    public array $searchable = [
        'docno' => '=',
        'order_type' => '=',
        'trans_status' => '=',
        'org_code' => '=',
        'status' => '=',

    ];

    /**
     * 时间格式化
     * @param $date
     * @return mixed
     */
    protected function serializeDate($date)
    {
        return $date->format('Y-m-d H:i');
    }

    public function getFields(){
        return $this->fields;
    }

    public function user(){
        return $this->hasOne(User::class,'id','creator_id');
    }

    /**
     * 返回订单明细
     * @return HasMany
     */
    public function detail()
    {
        return $this->hasMany(TransferOrderDetail::class,'order_id');
    }


}
